/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sinosoft.call.controller;

import com.alibaba.fastjson.JSONObject;
import com.sinosoft.call.entity.CallIndex;
import com.sinosoft.call.service.impl.BaseCallServiceImpl;
import com.sinosoft.enums.http.StatusCode;
import com.sinosoft.utils.logback.LogUtil;
import com.sinosoft.vo.http.Result;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author root
 */
@RestController
@RefreshScope
public class AccessController {

    @Autowired
    BaseCallServiceImpl cs;

    @Autowired
    CallIndex ci;

    @RequestMapping(value = "/{serviceCode}", method = {RequestMethod.POST, RequestMethod.GET})
    public Result access(@PathVariable(value = "serviceCode") String serviceCode, @RequestBody JSONObject param, HttpServletRequest request) {

        Result rj = cs.callService(serviceCode, param, ci);

        return rj;
    }

    @RequestMapping(value = "/api/v1/dispatcher/{serviceCode}", method = {RequestMethod.POST, RequestMethod.GET})
    public Object access00(@PathVariable(value = "serviceCode") String serviceCode, @RequestBody JSONObject param, HttpServletRequest request) {
        Object re = null;
        Result rj = cs.callService(serviceCode, param, ci);
        if(StatusCode.SUCCESS.getCode().equals(rj.getCode())){
            re = rj.getData();
        }else {
            re = rj;
        }
        return re;
    }

}
